# CalBMIv4.py
def main():
 while True:
    y_or_n = input('是否退出程序(y/n)？')
    if y_or_n == 'y':
        print('已退出程序')
        break
    else:   # 直到输入的是 y、n才退出循环
        while y_or_n == 'n':  # 如果输入为n，就执行下面的命令
            try:
                height, weight = eval(input("请输入身高(米)和体重(公斤)[逗号隔开]: "))
                bmi = weight / pow(height, 2)
                print("BMI 数值为：{:.2f}".format(bmi))
                who, nat = "", ""
                if bmi < 18.5:
                    who, nat = "偏瘦", "偏瘦"
                elif 18.5 <= bmi < 24:
                    who, nat = "正常", "正常"
                elif 24 <= bmi < 25:
                    who, nat = "正常", "偏胖"
                elif 25 <= bmi < 28:
                    who, nat = "偏胖", "偏胖"
                elif 28 <= bmi < 30:
                    who, nat = "偏胖", "肥胖"
                else:
                    who, nat = "肥胖", "肥胖"
                print("BMI 指标为:国际'{0}', 国内'{1}'".format(who, nat))
            except NameError:
                print('请输入正确的参数!')
            except SyntaxError:
                print('请用西式逗号分隔参数！')
            finally:
                print('---' * 20)
                y_or_n = input('是否退出程序(y/n)？')
if __name__ == '__main__':
    main()